<template>
	<el-main>
		<el-card class="box-card" shadow="never">
			<div class="search-box">
				<el-form :inline="true" :model="searchForm" class="demo-form-inline">
					<el-form-item label="状态">
						<el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
							<el-option label="进行中" value="1"></el-option>
							<el-option label="可购买" value="2"></el-option>
							<el-option label="已购买" value="3"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="砍价时间">
						<el-date-picker
							v-model="searchForm.time"
							type="daterange"
							value-format="YYYY-MM-DD"
							range-separator="至"
							start-placeholder="开始日期"
							end-placeholder="结束日期">
						</el-date-picker>
					</el-form-item>

					<el-form-item>
						<el-button type="primary" @click="onSubmit" icon="el-icon-search" >查询</el-button>
					</el-form-item>
				</el-form>
			</div>
			<div style="width:100%;height:0;border-bottom:#E4E7ED 1px dashed;margin-bottom: 10px"></div>
			<el-table
				:data="tableData"
				style="width: 100%;">
				<el-table-column
					prop="id"
					label="ID">
				</el-table-column>
				<el-table-column
					label="发起人">
					<template #default="scope">
						<div style="display: flex;align-items: center">
							ID: {{ scope.row.user_id }} | {{ scope.row.username }}
						</div>
					</template>
				</el-table-column>
				<el-table-column
					prop="name"
					width="500"
					label="活动名">
				</el-table-column>
				<el-table-column
					label="砍价进度">
					<template #default="scope">
						<div style="display: flex;align-items: center">
							{{ scope.row.progress * 100 }} %
						</div>
					</template>
				</el-table-column>
				<el-table-column
					prop="help_user_num"
					label="帮砍人数">
				</el-table-column>
				<el-table-column
					prop="already_cut_amount"
					label="已砍价格">
				</el-table-column>
				<el-table-column
					prop="leave_cut_amount"
					label="剩下的价格">
				</el-table-column>
				<el-table-column
					label="状态">
					<template #default="scope">
						<el-tag type="success" v-if="scope.row.status == 1">进行中</el-tag>
						<el-tag type="success" v-if="scope.row.status == 2">可购买</el-tag>
						<el-tag type="danger" v-if="scope.row.status == 3">已购买</el-tag>
					</template>
				</el-table-column>
				<el-table-column
					prop="create_time"
					width="160"
					label="发起时间">
				</el-table-column>
				<el-table-column
					prop="operation"
					label="操作">
					<template #default="scope">
						<el-button @click="handleDetail(scope.row)" type="text" size="small">详情</el-button>
					</template>
				</el-table-column>
			</el-table>

			<Pages :form="searchForm" :page-obj="page" @pageChange="handlePageChange" @pageJump="getList"></Pages>

			<el-dialog title="详情" v-model="dialogVisible" width="1200px" :close-on-click-modal="false" :destroy-on-close="true">
				<el-table
					:data="detailTable"
					style="width: 100%;">
					<el-table-column
						prop="id"
						label="ID">
					</el-table-column>
					<el-table-column
						label="帮砍人">
						<template #default="scope">
							<div style="display: flex;align-items: center">
								<img :src="scope.row.avatar" style="margin-right: 10px;width: 40px;height: 40px;"/>
								ID: {{ scope.row.user_id }}
							</div>
						</template>
					</el-table-column>
					<el-table-column
						prop="cut_amount"
						label="砍价金额">
					</el-table-column>
					<el-table-column
						prop="create_time"
						label="帮砍时间">
					</el-table-column>
				</el-table>
			</el-dialog>
		</el-card>
	</el-main>
</template>

<script>

import Pages from "@/components/pages/index.vue";

export default {
	name: 'links',
	components: {Pages},
	data() {
		return {
			searchForm: {
				status: '',
				time: '',
				limit: 15,
				page: 1
			},
			dialogVisible: false,
			page: {
				total: 0
			},
			tableData: [],
			loading: false,
			detailTable: []
		}
	},
	mounted() {
		this.getList()
	},
	methods: {
		// 获取列表
		async getList() {
			let res = await this.$API.bargain.orderList.get(this.searchForm)
			this.tableData = res.data.data
			this.total = res.data.total
		},
		// 搜索
		onSubmit() {
			this.searchForm.page = 1
			this.getList()
		},
		// 分页
		handlePageChange(page) {
			this.searchForm.page = page
			this.getList()
		},
		async handleDetail(row) {
			let res = await this.$API.bargain.orderDetail.get({id: row.id})
			this.detailTable = res.data
			this.dialogVisible = true
		}
	}
}
</script>

<style scoped>
.el-button--small {
	padding: 0 !important;
}
</style>
